package com.bos.web.action;
import com.bos.domian.base.TakeTime;
import com.bos.service.TakeTimeService;
import com.bos.web.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import java.util.Date;
import java.util.List;
/**
 * @author misterWei
 * @create 2018年11月16号:09点38分
 * @mailbox mynameisweiyan@gmail.com
 */
//需要进行异步操作,所以返回值也是json类型的,  json-default是集成struts-default,所以不需要考虑拦截器链加载问题
@ParentPackage("json-default")
@Actions
@Namespace("/")
@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)//多例的
public class TakeTimeAction extends BaseAction<TakeTime> {

    @Autowired
    private TakeTimeService takeTimeService;

    String takeTimeids;

    public void setTakeTimeids(String takeTimeids) {
        this.takeTimeids = takeTimeids;
    }

    //保存以及更新的操作
    @Action(value = "takeTimeSaveOrUpdate", results = {@Result(location = "/pages/base/take_time.html")})
    public String takeTimeSaveOrUpdate() {
        model.setOperatingTime(new Date());
        takeTimeService.takeTimeSaveOrUpdate(model);
        return SUCCESS;
    }
    @Action(value = "taketime_pageQuery", results = {@Result(name = "success", type = "json")})
    public String standardPageQuery() {
        //存入值栈                                                  //分页都是从第0页开始的!
        ActionContext.getContext().getValueStack().push(takeTimeService.takeTimePageQuery(page - 1, rows));
        return "success";
    }
    @Action(value = "takeTime_delete", results = {@Result(name = "success", type = "json")})
    public String takeTimeDelete() {
        String[] splitIds = takeTimeids.split(",");
        takeTimeService.takeTimeDelete(splitIds);

        try {
            ActionContext.getContext().getValueStack().push(true);
            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            ActionContext.getContext().getValueStack().push(false);
            return SUCCESS;
        }

    }

    @Action(value = "takeTime_findAll",results = {@Result(type = "json")})
    public String takeTimeFindAll(){
       List<TakeTime> takeTimeList =  takeTimeService.findAll();
       ActionContext.getContext().getValueStack().push(takeTimeList);
        return SUCCESS;
    }
}
